#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>

typedef struct ListNode
{
	int val;
	struct ListNode* next;
} ListNode;

ListNode* MidNode(ListNode* phead)
{
    ListNode* slow, * fast;
    slow = fast = phead;
    while (fast != NULL && fast->next != NULL)
    {
        slow = slow->next;
        fast = fast->next->next;
    }
    return slow;
}
ListNode* ReverseList(ListNode* phead)
{
    if (phead == NULL)
    {
        return phead;
    }
    ListNode* n1 = NULL, * n2 = phead, * n3 = n2->next;
    while (n2 != NULL)
    {
        n2->next = n1;
        n1 = n2;
        n2 = n3;
        if (n3 != NULL)
            n3 = n3->next;
    }
    return n1;
}
